 public class Demo1 {
    public static final int val = 20_0000_0000;
    public static void fun1() {
        int a = 0;
        long beg = System.currentTimeMillis();
        for (long i = 0; i < val; i++) {
            a++;
        }

        a = 0;
        for (long i = 0; i < val; i++) {
            a++;
        }

        long end = System.currentTimeMillis();
        System.out.println("单线程的执行时间是:" + (end - beg) + "ms");
    }


     public static void fun2() {

         long beg = System.currentTimeMillis();
         Thread t = new Thread(() -> {
             int a = 0;
             for (long i = 0; i < val; i++) {
                 a++;
                 System.out.println("Hello World");
             }
         });

         Thread t1 = new Thread(() -> {
             int a = 0;
             for (long i = 0; i < val; i++) {
                 a++;
                 System.out.println("Hello Main");
             }
         });

         t.start();
         t1.start();

         try {
             t.join();
             t1.join();
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
         long end = System.currentTimeMillis();
         System.out.println("单线程的执行时间是:" + (end - beg) + "ms");
     }
    public static void main(String[] args) {
           // fun1();
            fun2();
    }
}
